<template>    
    <el-container class="home_container">
        <!-- 头部区域 -->
        <el-header>
            <div>
                <img class="logo" src="../assets/logo.png" alt="">
                <span>电商后台管理系统</span>
            </div>
            <el-button type="info" @click="logout">退出</el-button>
        </el-header>
        <!-- 页面主题区域 -->
        <el-container>
            <!-- 左侧菜单栏 -->
            <el-aside :width="is_toggle_bool ? '64px' : '200px'">
                <!-- 侧边栏折叠按钮 -->
                <div class="toggle_menu" @click="toggle_button">|||</div>
            <el-menu
                :collapse="is_toggle_bool"
                :collapse-transition="false"
                background-color="#333744"
                text-color="#fff"
                active-text-color="#409eff"
                unique-opened
                router
                :default-active="active_path">
                <!-- 一级菜单 -->
                <el-submenu :index="item.path + ''" v-for="item of menulist" :key="item.id">
                    <!-- 一级菜单模板区域 -->
                    <template slot="title">
                        <!-- 图标 -->
                    <i :class="icon_obj[item.id]"></i>
                    <!-- 文本 -->
                    <span>{{item.authName}}</span>
                    </template>
                    <!-- 二级菜单 -->
                    <el-menu-item 
                        v-for="in_item of item.children" :key="in_item.id" 
                        :index="'/' + in_item.path" 
                        @click="save_nav_status('/' + in_item.path)"
                    >
                        <i class="el-icon-menu"></i>
                        <!-- 文本 -->
                        <span>{{in_item.authName}}</span>
                    </el-menu-item>
                </el-submenu>
                </el-menu>
            </el-aside>
            <!-- 右侧内容主体 -->
            <el-main>
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>
<script>
export default {
    data() {
        return{
            // 左侧菜单数据
            menulist: [],
            icon_obj: {
                "125" : "iconfont icon-users",
                "103" : "iconfont icon-tijikongjian",
                "101" : "iconfont icon-gouwudai",
                "102" : "iconfont icon-danju-tianchong",
                "145" : "iconfont icon-baobiao",
            },
            is_toggle_bool:false,
            active_path:''
        }
    },
    created(){
        this.getMessageList(),
        this.active_path = window.sessionStorage.getItem("active_path")
    },
    methods: {
        logout(){
            window.sessionStorage.clear();
            this.$router.push("/login")
        },
        // 获取左侧菜单数据
        async getMessageList(){
            let {data: res} = await this.axios.get("menus");
            if(res.meta.status !== 200) return this.message.error(res.meta.msg)
            this.menulist = res.data
            // console.log(res)
        },
        // 左侧菜单栏折叠按钮，点击按钮切换 is_toggle_bool 的布尔值
        toggle_button(){
            this.is_toggle_bool = !this.is_toggle_bool
        },
        save_nav_status(active_path){
            window.sessionStorage.setItem("active_path",active_path)
        }
    },

}
</script>
<style lang="less" scoped>
.home_container{
    height: 100%;
}
.el-header{
    background-color: #373d41;
    display: flex;
    justify-content: space-between;
    padding-left: 0;
    align-items: center;
    span{
        font-size: 20px;
        color: #fff;
        margin-left: 15px;
    }
    >div{
        display: flex;
        align-items: center;

    }
}
.el-aside{
    background-color: #333744;
    .el-menu{
        border: none;
    }
}
.el-main{
    background-color: #eaedf1;
}
.iconfont{
    margin-right: 10px;
}
.toggle_menu{
    font-size: 10px;
    background-color: #4a5064;
    line-height: 24px;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
    color: #fff;
}
.logo{
    width: 40px;
    margin-left: 15px;
}
</style>